#include "head.h"

int main(){

    char *port = "8080";
    char *ip = "192.168.40.128";

    int socket_fd = socket(AF_INET, SOCK_STREAM, 0);

    struct sockaddr_in sockaddr;
    sockaddr.sin_family = AF_INET;
    sockaddr.sin_port = htons(atoi(port));
    sockaddr.sin_addr.s_addr = inet_addr(ip);

    int conn_err = connect(socket_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
    ERROR_CHECK(conn_err, -1, "connect");

    cmsg_t client;
    memset(&client, 0, sizeof(client));
    order_t order_s;

    while(1){
        //从stdin读取命令
        memset(&order_s, 0, sizeof(order_s));
        read_stdin(&order_s);

        /* printf(" 000 \n"); */
        //分发命令
        if(client.log_st == 0){
            if(order_s.order > 6){
                send(socket_fd, &order_s, sizeof(order_s), 0);
            }

            if(order_s.order == RGST){
                printf("goto rgst\n");
            }else
                if(order_s.order == LOGIN){
                    printf("goto login\n");
                    client.log_st = 1;
                }
        }else{
            if(order_s.order < 7 && order_s.order != -1){
                send(socket_fd, &order_s, sizeof(order_s), 0);
            }

            switch(order_s.order){
            case CD:
                printf("goto cd\n");
                break;
            case LS:
                printf("goto ls\n");
                break;
            case PUTS:
                printf("goto puts\n");
                break;
            case GETS:
                printf("goto gets\n");
                break;
            case RM:
                printf("goto rm\n");
                break;
            case MKDIR:
                printf("goto mkdir\n");
                break;
            case PWD:
                printf("goto pwd\n");
                break;
            }
        }
    }

    close(socket_fd);
    return 0;
}

